package server.business.task.handler;

import com.core.initialize.Message;
import com.google.protobuf.GeneratedMessage;

import server.ScriptEnum;
import server.ServerEngin;
import server.ServerHandler;
import server.business.login.ILoginScript;
import server.business.login.LoginScript;
import server.business.task.ITaskScript;
import server.business.task.TaskScript;
import server.business.task.config.TaskConfig;
import server.business.task.data.Task;
import server.commonData.User;
import server.msgBean.LoginMessage.TaskAwardReq;

public class TaskAwardHandler extends ServerHandler {

	@Override
	public Class<? extends GeneratedMessage> initBodyClass()
	{
		return TaskAwardReq.class;
	}

	@Override
	protected void handler(Message msg, User user) throws Throwable
	{
		TaskAwardReq req = msg.getBody();
		Task task = user.getTaskList().getTaskList().get(req.getTaskId());
		if(task==null||task.isAward()||!task.isCanAward())
			return;
		TaskConfig config = task.getConfig();
		user.addMoney(config.awardMoney);
		
		task.setAward(true);
		//刷新金币等
		ILoginScript scripte = ServerEngin.getInstance().getScriptM().getScript(ScriptEnum.LOGIN_SCRIPT);
		scripte.refrechVipMoneyGoldInfo(user);
		//刷新任务列表
		ITaskScript script = ServerEngin.getInstance().getScriptM().getScript(ScriptEnum.TASK_SCRIPT);
		script.refreshTaskListClient(user);
	}
}
